package com.neusoft.elmboot.service.Impl;

import com.neusoft.elmboot.mapper.CartMapper;
import com.neusoft.elmboot.po.Cart;
import com.neusoft.elmboot.service.CartService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.List;

@Service
public class CartServiceImpl implements CartService {

    private static final Logger logger = LoggerFactory.getLogger(CartServiceImpl.class);

    @Autowired
    private CartMapper cartMapper;

    @Override
    public List<Cart> listCart(Cart cart) {
        try {
            return cartMapper.listCart(cart);
        } catch (Exception e) {
            logger.error("Error occurred while fetching cart list. Cart: {}", cart, e);
            throw new RuntimeException("Failed to fetch cart list. Please try again later.");
        }
    }

    @Override
    public int saveCart(Cart cart) {
        try {
            return cartMapper.saveCart(cart);
        } catch (Exception e) {
            logger.error("Error occurred while saving cart. Cart: {}", cart, e);
            throw new RuntimeException("Failed to save cart. Please try again later.");
        }
    }

    @Override
    public int updateCart(Cart cart) {
        try {
            return cartMapper.updateCart(cart);
        } catch (Exception e) {
            logger.error("Error occurred while updating cart. Cart: {}", cart, e);
            throw new RuntimeException("Failed to update cart. Please try again later.");
        }
    }

    @Override
    public int removeCart(Cart cart) {
        try {
            return cartMapper.removeCart(cart);
        } catch (Exception e) {
            logger.error("Error occurred while removing cart. Cart: {}", cart, e);
            throw new RuntimeException("Failed to remove cart. Please try again later.");
        }
    }
}





















//package com.neusoft.elmboot.service.Impl;
//
//import com.neusoft.elmboot.mapper.CartMapper;
//import com.neusoft.elmboot.po.Cart;
//import com.neusoft.elmboot.service.CartService;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.stereotype.Service;
//
//import java.util.List;
//@Service
//public class CartServiceImpl implements CartService{
//
//    @Autowired
//    private CartMapper cartMapper;
//    @Override
//    public List<Cart> listCart(Cart cart) {
//        return cartMapper.listCart(cart);
//    }
//
//    @Override
//    public int saveCart(Cart cart) {
//        return cartMapper.saveCart(cart);
//    }
//
//    @Override
//    public int updateCart(Cart cart) {
//        return cartMapper.updateCart(cart);
//    }
//
//    @Override
//    public int removeCart(Cart cart) {
//        return cartMapper.removeCart(cart);
//    }
//}